package com.mingqijia.gassafety.authority.api.web.facade;

import com.mingqijia.gassafety.authority.api.req.config.*;
import com.mingqijia.gassafety.authority.api.resp.config.DictionaryItemRespDTO;
import com.mingqijia.gassafety.authority.api.resp.config.DictionaryRespDTO;
import com.mingqijia.gassafety.shared.constant.OperateRecordEnum;
import com.mingqijia.gassafety.shared.log.LogRecord;
import com.mingqijia.gassafety.shared.utils.commonUtils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 字典配置REST接口
 * @author Damon S.
 * @version v1.0.1
 * @date 2021年04月13日 18:42
 */
@Api(tags = "控制台--字典")
@RequestMapping(value = "/console/v1/dictionaries", produces = MediaType.APPLICATION_JSON_VALUE)
public interface DictionaryManageFacade {

    @GetMapping("/duplication")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "字典名称", dataType = "String"),
            @ApiImplicitParam(name = "code", value = "字典编码", dataType = "String")
    })
    @ApiOperation(value = "字典判重", notes = "判断字典名称和编码是否重复：0-无重复，1-名称重复，2-编码重复")
    Integer checkDictDuplication(@RequestParam("name")String name, @RequestParam("code")String code);

    @GetMapping("/items/duplication")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictCode", value = "字典编码", dataType = "String"),
            @ApiImplicitParam(name = "name", value = "字典类型名称", dataType = "String"),
            @ApiImplicitParam(name = "code", value = "字典类型取值", dataType = "String")
    })
    @ApiOperation(value = "字典类型判重", notes = "判断名称和编码是否重复：0-无重复，1-名称重复，2-编码重复")
    Integer checkDictItemDuplication(@RequestParam("dictCode")String dictCode, @RequestParam("name")String name, @RequestParam("code")String code);

    @GetMapping("/duplicate/{spId}")
    @ApiImplicitParam(name = "spId", value = "企业编码", dataType = "String")
    @ApiOperation(value = "复制企业字典", notes = "根据平台配置复制企业字典")
    void duplicateParams2Company(@PathVariable String spId);

    @GetMapping("/{dictCode}")
    @ApiImplicitParam(name = "dictCode", value = "字典编码", dataType = "String")
    @ApiOperation(value = "获取字典", notes = "返回字典信息")
    DictionaryRespDTO findDictByCode(@PathVariable String dictCode);

    @GetMapping
    @ApiOperation(value = "查询字典", notes = "分页字典列表")
    PageUtil<DictionaryRespDTO> findDictionary(@Valid QueryDictionaryReqDTO req);

    @GetMapping("/items/{dictCode}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictCode", value = "字典编码", dataType = "String"),
            @ApiImplicitParam(name = "name", value = "字典类型名称", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页号", dataType = "Long"),
            @ApiImplicitParam(name = "pageSize", value = "页宽", dataType = "Long")
    })
    @ApiOperation(value = "获取字典类型", notes = "返回字典类型列表")
    PageUtil<DictionaryItemRespDTO> findDictionaryItem(@PathVariable String dictCode,
                                                       String name,
                                                       @RequestParam(required = false) Long page,
                                                       @RequestParam(required = false) Long pageSize);

    @PostMapping
    @ApiOperation(value = "新增字典", notes = "返回新增字典Id")
    String createDictionary(@RequestBody@Valid CreateDictionaryReqDTO req);
    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_34)
    @PostMapping("/items")
    @ApiOperation(value = "新增字典类型", notes = "返回新增字典类型Id")
    String createDictionaryItem(@RequestBody @Valid CreateDictionaryItemReqDTO req);

    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_35)
    @PutMapping
    @ApiOperation(value = "更新字典", notes = "返回是否更新成功")
    void updateDictionary(@RequestBody @Valid UpdateDictionaryReqDTO req);
    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_35)
    @PutMapping("/items")
    @ApiOperation(value = "更新字典类型", notes = "返回是否更新成功")
    void updateDictionaryItem(@RequestBody @Valid UpdateDictionaryItemReqDTO req);

    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_36)
    @DeleteMapping("/{dictId}")
    @ApiImplicitParam(name = "dictId", value = "字典Id", dataType = "String")
    @ApiOperation(value = "删除字典", notes = "返回是否删除成功")
    void removeDictionary(@PathVariable String dictId);
    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_37)
    @DeleteMapping("/items")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "字典类型Id列表(多个逗号间隔)", dataType = "String", required = true),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "String")
    })

    @ApiOperation(value = "删除字典类型", notes = "返回是否删除成功")
    void removeDictionaryItem(@RequestParam String itemId,String code);

    @PutMapping("/{dictId}/{state}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictId", value = "字典Id", dataType = "String"),
            @ApiImplicitParam(name = "state", value = "启用状态", dataType = "String")
    })
    @ApiOperation(value = "字典上下线(0停用，1启用)", notes = "返回是否成功")
    void switchDictionary(@PathVariable String dictId, @PathVariable Integer state);
}
